//
//  SecondTableViewCell.m
//  NewProject
//
//  Created by 王嘉琪 on 2017/6/8.
//  Copyright © 2017年 李航飞. All rights reserved.
//

#import "SecondTableViewCell.h"

@implementation SecondTableViewCell
//重写cell创建方法
//-(instancetype)initWithResueIdentifier:(NSString*)identifier;{
//    self = [super initWithStyle:0 reuseIdentifier:identifier];
//    if (self) {
//        [self setUpView];
//    }
//    return self;
//}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setUpView];
    }
    return self;
}

- (void)setUpView{
    _firstImg =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 90, 90)];
    [_firstImg setImage:[UIImage imageNamed:@"xigua"]];
    [self addSubview:_firstImg];
    //    _messageLabel.backgroundColor=[UIColor redColor];
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(5, 90, [UIScreen mainScreen].bounds.size.width-5, 1)];
    view.backgroundColor=LINE_COLOE_245;
    [self addSubview:view];
    [self addSubview:_firstImg];
    
    UILabel *linshi=[[UILabel alloc] initWithFrame:CGRectMake(90, 5, [UIScreen mainScreen].bounds.size.width/4*3-90, 40)];
    [self addSubview:linshi];
//    linshi.text=@"【雪碧】清爽柠檬味汽水";
//    _jingxuanImg=[[UIImageView alloc] initWithFrame:CGRectMake(0, 15, 30, 15)];
//    [_jingxuanImg setImage:[UIImage imageNamed:@"jingx2"]];
//    [linshi addSubview:_jingxuanImg];
//    _nameLable =[[UILabel alloc] initWithFrame:CGRectMake(30, 0, linshi.frame.size.width-30, 45)];
    linshi.numberOfLines = 2;
    [linshi setFont:[UIFont systemFontOfSize:14]];
    
    
    NSMutableAttributedString *attri =    [[NSMutableAttributedString alloc] initWithString:@"【雪碧】清爽柠檬味汽水500ml"];
    
    NSTextAttachment *attch = [[NSTextAttachment alloc] init];
    
    attch.image = [UIImage imageNamed:@"jingx2"];
    
    attch.bounds = CGRectMake(0, 0, 30, 15);
    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
    
    [attri insertAttributedString:string atIndex:0];
    
    linshi.attributedText = attri;
    
    _jiageLable =[[UILabel alloc] initWithFrame:CGRectMake(90, 50, ([UIScreen mainScreen].bounds.size.width/4*3-90)/2, 40)];
    [self addSubview:_jiageLable];
    
    NSMutableAttributedString *attri2 =    [[NSMutableAttributedString alloc] initWithString:@"￥3.5  "];
    
    NSTextAttachment *attch2 = [[NSTextAttachment alloc] init];
    
    attch2.image = [UIImage imageNamed:@"yix2"];
    
    attch2.bounds = CGRectMake(0, 0, 40, 15);
    NSAttributedString *string2 = [NSAttributedString attributedStringWithAttachment:attch2];
    
    
    [attri2 insertAttributedString:string2 atIndex:[attri2 length]];
    _jiageLable.textColor=[UIColor colorWithRed:255/255.0 green:126/255.0 blue:0/255.0 alpha:1];
    [_jiageLable setFont:[UIFont systemFontOfSize:14]];
    _jiageLable.attributedText = attri2;
    
    UIView *jiaAndJian=[[UIView alloc] initWithFrame:CGRectMake(_jiageLable.frame.origin.x+_jiageLable.frame.size.width, 50, [UIScreen mainScreen].bounds.size.width/4, 40)];
//    jiaAndJian.backgroundColor=[UIColor redColor];
    [self addSubview:jiaAndJian];

    _jianBtn =[[UIButton alloc] initWithFrame:CGRectMake(0, (40-jiaAndJian.frame.size.width/3)/2, jiaAndJian.frame.size.width/3, jiaAndJian.frame.size.width/3)];
    [_jianBtn setImage:[UIImage imageNamed:@"jianx2"] forState:UIControlStateNormal];
    [_jianBtn addTarget:self action:@selector(changeNum:) forControlEvents:UIControlEventTouchUpInside];
    [jiaAndJian addSubview:_jianBtn];
    _jianBtn.tag=100;
    _jiaBtn =[[UIButton alloc] initWithFrame:CGRectMake(jiaAndJian.frame.size.width/3*2-10, (40-jiaAndJian.frame.size.width/3)/2, jiaAndJian.frame.size.width/3, jiaAndJian.frame.size.width/3)];
    [_jiaBtn setImage:[UIImage imageNamed:@"加x2"] forState:UIControlStateNormal];
    [_jiaBtn addTarget:self action:@selector(changeNum:) forControlEvents:UIControlEventTouchUpInside];
    [jiaAndJian addSubview:_jiaBtn];
    _jiaBtn.tag=200;
    _shuliangLable =[[UILabel alloc] initWithFrame:CGRectMake(_jianBtn.frame.size.width+_jianBtn.frame.origin.x, _jianBtn.frame.origin.y, _jiaBtn.frame.origin.x-_jianBtn.frame.origin.x-_jianBtn.frame.size.width, 30)];
    [_shuliangLable setText:@"0"];
    _shuliangLable.font=[UIFont systemFontOfSize:12];
    _shuliangLable.tintColor=[UIColor blackColor];
    _shuliangLable.textAlignment = UITextAlignmentCenter;
    [jiaAndJian addSubview:_shuliangLable];
    
    
}
- (void)changeNum:(UIButton *)btn{
//    self.block(btn);
    NSLog(@"123123");
    if (btn.tag == 100) {
        if (self.indexNum>0) {
            self.indexNum--;
        }
        
    }else{
        self.indexNum++;
    }
    
    self.shuliangLable.text = [NSString stringWithFormat:@"%ld",self.indexNum];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.shuliangLable.text = [NSString stringWithFormat:@"%ld",self.indexNum];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
